package com.swq.java.code.chapter18.code25;

import com.swq.java.code.utils.Values;

import java.io.*;
import java.nio.channels.*;

public class LockTester {
    public static void main(String args[]) throws Exception {
        FileOutputStream fos = new FileOutputStream(Values.testFileName);
        FileLock fl = fos.getChannel().tryLock();
        if (fl != null) {
            System.out.println("Locked File");
            System.out.println(fl.isShared());
            Thread.sleep(60000);  //锁定文件60秒
            fl.release();
            System.out.println("Released Lock");
        }
    }
}
